Pro iPhone Development with Swift 5 by Wallace Wang

Pro iPhone Development with Swift 5 by Wallace Wang

Author:Wallace Wang
Language: eng
Format: epub
ISBN: 9781484249444
Publisher: Apress


2.Create the user interface exactly as you created the AccelerateApp in the previous example with an enlarged label connected to the IBOutlet in the ViewController.swift file.

3.Click the ViewController.swift file in the Navigator pane.

4.Edit the ViewController.swift file so the entire file looks like the following:import UIKit

import CoreMotion

class ViewController: UIViewController {

@IBOutlet var myLabel: UILabel!

let motionManager = CMMotionManager()

override func viewDidLoad() {

super.viewDidLoad()

// Do any additional setup after loading the view.

if motionManager.isMagnetometerAvailable {

motionManager.magnetometerUpdateInterval = 0.5

motionManager.startMagnetometerUpdates(to: OperationQueue.main) { (motion, error) -> Void in

if let trackMotion = motion {

let userField = trackMotion.magneticField

let displayText = "x: \(userField.x) \ny: \(userField.y) \nz: \(userField.z)"

DispatchQueue.main.async {

self.myLabel.text = displayText

}

}

}

}

}



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.